package com.qiankun.tang.ui.view.adapter.home;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.common.library.listener.OnAppListener;
import com.common.library.ui.view.adapter.base.BaseRecyclerAdapter;
import com.facebook.drawee.view.SimpleDraweeView;
import com.qiankun.tang.R;
import com.qiankun.tang.beans.VideoSynopsisBean;

/**
 * @author txf
 * @Title
 * @package com.qiankun.video.ui.view.adapter
 * @date 2017/6/9 0009
 */

public class VideoSynopsisAdapter extends BaseRecyclerAdapter<VideoSynopsisBean> {
    public VideoSynopsisAdapter(Context context) {
        super(context);
    }
    public VideoSynopsisAdapter(Context context, OnAppListener.OnInteractionListener listener) {
        super(context, listener);
    }
    @Override
    public int getItemViewType(int position) {
        return getDatas().get(position).getType();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case 0:
                return new VideoSynopsisHolder0(LayoutInflater.from(getContext()).inflate(R.layout.item_video_synopsis_0, parent, false));
            case 1:
                return new VideoSynopsisHolder1(LayoutInflater.from(getContext()).inflate(R.layout.item_video_synopsis_1, parent, false));
        }
        return null;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof VideoSynopsisHolder0) {
            onBindVideoSynopsisHolder0((VideoSynopsisHolder0) holder, position);
        } else if (holder instanceof VideoSynopsisHolder1) {
            onBindVideoSynopsisHolder1((VideoSynopsisHolder1) holder, position);
        }
    }
    private void onBindVideoSynopsisHolder1(VideoSynopsisHolder1 holder, int position) {
        final VideoSynopsisBean bean = getDatas().get(position);
        holder.mImge.setImageURI(bean.getImgUrl());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getListener().onInteraction(1, bean);
            }
        });
    }
    private void onBindVideoSynopsisHolder0(VideoSynopsisHolder0 holder, int position) {
        final VideoSynopsisBean bean = getDatas().get(position);
        holder.mImge.setImageURI(bean.getImgUrl());
        holder.mSubTitle.setText(bean.getSubtitle());
        holder.mTitle.setText(bean.getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getListener().onInteraction(0, bean);
            }
        });
    }

    private class VideoSynopsisHolder0 extends RecyclerView.ViewHolder {
        SimpleDraweeView mImge;
        TextView mTitle, mSubTitle;

        public VideoSynopsisHolder0(View item) {
            super(item);
            mImge = (SimpleDraweeView) itemView.findViewById(R.id.item_video_synopsis_0_img);
            mTitle = (TextView) itemView.findViewById(R.id.item_video_synopsis_0_title);
            mSubTitle = (TextView) itemView.findViewById(R.id.item_video_synopsis_0_subtitle);
        }
    }

    private class VideoSynopsisHolder1 extends RecyclerView.ViewHolder {
        SimpleDraweeView mImge;

        public VideoSynopsisHolder1(View item) {
            super(item);
            mImge = (SimpleDraweeView) itemView.findViewById(R.id.item_video_synopsis_1_img);
        }
    }
}
